<style>

</style>
<div class="fixed-bar">
    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url('')}" method="get" id="hisi-table-search">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">订单号</label>
                <div class="layui-input-inline">
                    <input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
               <label class="layui-form-label ">数据月份</label>
               <div class="layui-input-inline">
                   <input type="text" name="create_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="统计月份" class="layui-input">
               </div>
           </div>
           <div class="layui-inline">
               <label class="layui-form-label">科目名称</label>
                <div class="layui-input-inline" style="width:120px;">
                    <input type="text" name="reason" lay-verify="" placeholder="科目名称"  class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
               <label class="layui-form-label">录入人</label>
                <div class="layui-input-inline">
                    <input type="text" name="creater" lay-verify="" placeholder="录入人" style="width:120px;" class="layui-input">
                </div>
            </div>
           
			<div class="layui-inline">
                <button type="submit" id="seacher" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
                <!-- <button type="button" class="layui-btn layui-btn-primary hisi-export">导出</button>-->
            </div>
        </div>
    </form>
</div>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">

  	<ul class="layui-tab-title" id="vue_tab_content">
        <li><a href="{:url('incomeOutList')}">入账管理</a></li>
        <li class="layui-this"><a href="{:url('corpPayoutList')}">费用管理</a></li>
        <li><a href="{:url('corpAssetsList')}">经营资产</a></li>
        <li style="float:right;width:510px;margin-bottom:3px;">
        	<button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="test9">选择文件导入</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="test10">导入</button>
            <a style="display:inline-block" href="__STATIC__/demo/order-income-delo.xlsx" target="_blank" title="点击下载导入的xls模板"><i class="layui-icon">&#xe62d;</i>导入模板exl</a>
        </li>
    </ul>
    <div class="layui-tab-content">
        <div id="returnData"><table id="dataTable" lay-filter="dataTable"></table></div>
        
        <div id="deliverLog">
            
        </div>
    </div>
</div>      
{include file="system@block/layui" /}

<script type="text/html" id="materialInfoTpl">
{{layui.tool.formatMaterialType(d.rttype, '', 2)}}
<span class="copy-item">{{ d.name }}</span> <br>
<span class="copy-item">{{ d.model }}</span> <br>
<span class="copy-item">{{d.colornum}} / {{d.color}}</span>
</script>
<script type="text/html" id="toolbar">
	<a href="{:url('skuStockLog')}" title="新增入账" class="hisi-iframe layui-btn layui-btn-sm tail-defective" hisi-data="{width: '50%', height: '50%'}">新增费用</a>
	&nbsp;&nbsp;<a href="{:url('')}?action=payoutDetailList" title="费用数据明细" class="hisi-iframe layui-btn layui-btn-sm tail-defective" hisi-data="{width: '100%', height: '100%'}">数据明细</a>  
</script>

<script type="text/javascript">
    layui.use(['table', 'opTable', 'laydate', 'form', 'laytpl','cookie','tool','layer','upload'], function() {
        var $ = layui.jquery;
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;
        var layer = layui.layer;
        var upload = layui.upload;
		laydate.render({
			elem: '#create_date_range'
			,range: '~'
			,theme: 'molv'
			,mark: {'{:$today}':''}
			,change: function(value, date, endDate){
				$('#create_date_range').val(value);
		            	$('#layui-laydate1').remove();//关闭面板
		            }
		});
		
        var formData;
        form.on('submit(demo1)', function (data) {
            //表单数据formData
            formData = data.field;
             
        });
        //自定页
        window.statCli = function(status) {
            if(status==4 ){
                $('#layui-table-page1').attr('id', 'layui-table-page2');
                $("#deliverLog").show();
                $("#returnData,.fixed-bar").hide();
                $("#deliverLog").load("{:url('deliveryPrint')}");
            }else if(status==5){
                $('#layui-table-page2').attr('id', 'layui-table-page3');
                $('#layui-table-page1').attr('id', 'layui-table-page2');
                $("#deliverLog").show();
                $("#returnData,.fixed-bar").hide();
                $("#deliverLog").load("{:url('deliveryLog')}");
            }else{
                $('#returnData,.fixed-bar').show();
                $('#deliverLog').hide();
                var url='{:url()}?status='+status;
                $("#hisi-table-search").attr('action',url)
                $("#seacher").click();
            }
            form.render();
		}

        var opTable = layui.opTable.render({
            elem: '#dataTable'
            ,url: '{:url("")}' //数据接口
            //,id:'dataTable'
            ,page: true //开启分页
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
			,openVisible: false
            //,cellMinWidth: 80
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ // 编号 核算维度 入帐科目名称 凭证 汇总金额 月份 录入人 录入时间 操作 
                {field:'pic',title : '核算维度', templet:function(d){return '车间/裁床';}}
				,{field:'admin_id_name',title : '费用科目名称',templet:function(d){return '销售收入';}}
				,{field: 'name', title: '凭证'}
				,{field: 'assign_factory', title: '分配工厂'}
				,{field: 'data_count', title: '订单数'}
				,{field:'payment_total',title : ' 汇总金额'}
				,{field: 'pay_month', title: '月份'}
                ,{field:'create_admin',title : '录入人'}
				,{field: 'create_time', title: '录入时间'}
				,{field: '', title: '操作', templet: '#buttonTpl',width:150} 
            ]]
            ,done: function(res, curr, count){
				var data=res.data;
                for (var i in data){
                    $('#stall-ids-'+data[i]['id']).val(data[i]['stalls_id']);
                }
                layui.form.render();
				for (var i in data){
					var nowtime=new Date();
					var dataid=data[i]['id'];
                    //if(data[i]['giveback_time']=='') value=nowtime.getFullYear()+"-"+(nowtime.getMonth()+1)+"-01";
                    laydate.render({
                        elem: "#stall_order_time"+data[i]['id'], //指定元素
                        value: '',
						 done: function(value, date){
							var str=this.elem.selector;
							var dataid=str.replace(/#stall_order_time/, "");
							$.ajax({
								type: "POST",
								url: "{:url('status')}",
								data: "id="+dataid+"&action=setFieldVal&field=giveback_time&fieldval="+value,
								dataType:"json",
								success: function(res){
									if (res.code == 1) {
										layer.msg(res.msg, {icon: 1,time:600});
									} else {
										layer.msg(res.msg, {icon: 2,anim: 6,time:600});
									}
								}
							});
						 }
                    });
                    $('#stall_order_time'+data[i]['id']).val(data[i]['giveback_time']);
                }
                //layui.form.render();
				
                opTable.openAll();
                if (res.statData != []) {
                    var total=0,stat=res.statData,abolishNum=res.abolishNum;
                    for(var i in stat) {
                         total= total+Number(stat[i]);
                    }
                }
            }
        });
        //导入金鹏加工单
        upload.render({
            elem: '#test9'
            ,url: "{:url('corpPayoutList')}?action=impPayoutData" //改成您自己的上传接口
            ,auto: false
            //,multiple: true
            ,bindAction: '#test10'
            , accept: 'file'
            ,done: function(res){
                if(res.code==2){
                    var order=res.data.order,sku=res.data.sku,size=res.data.size,existdata=res.data.existdata;
                    var content="";
                    var countOrder = order.length;
                    var countSku = sku.length;
                    var countSize = size.length;
                    content += '<tr>';
                    content += '<td>导入失败提示</td><td>';
                    for (var i in existdata){
                        content += '<span class="copy-item">' + existdata[i] + '</span> &nbsp&nbsp;';
                    }
                    content +='</td></tr>';
                    layer.open({
                        type: 1
                        ,title:'导入失败请完善'
                        ,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                        ,id: 'layerDemoauto' //防止重复弹出
                        ,content: '<table class="layui-table">'+content+'</table>'
                        ,btn: '关闭全部'
                        ,area: ['800px','400px']
                        ,btnAlign: 'c' //按钮居中
                        ,shade: 0 //不显示遮罩
                        ,yes: function(){
                            layer.closeAll();
                        }
                    });
                }else{
                    layer.msg(res.msg);
                    var existdata=res.data.existdata,success_count=res.data.success_count;

                    var content="";
                    content += '<tr><td>成功个数</td><td>成功导入 '+success_count+'条记录</td></tr>';
                    content += '<tr>';
                    content += '<td>重复导入</td><td>';
                    if(existdata.length>0){
                        content +="以下重复的未做导入，如需导入请手工增加<br> "
                    }
                    for (var i in existdata){
                        content += '<span class="copy-item">' + existdata[i] + '</span> &nbsp;||&nbsp; ';
                    }
                    content +='</td></tr>';
                    layer.open({
                        type: 1
                        ,title:'导入成功'
                        ,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                        ,id: 'layerDemoauto' //防止重复弹出
                        ,content: '<table class="layui-table">'+content+'</table>'
                        ,btn: '关闭全部'
                        ,area: ['800px','400px']
                        ,btnAlign: 'c' //按钮居中
                        ,shade: 0 //不显示遮罩
                        ,yes: function(){
                            layer.closeAll();
                        }
                    });
                }
            }
        });

        $('#deliverLog').hide();
    });
</script>